<?php


namespace app\admin\controller;


use app\common\controller\Common;
use app\admin\logic\AppLogic;

/**
 * app信息
 * Class AppInfo
 * @package app\admin\controller
 * @author Mr.Li
 * @create 2021-08-23 15:51
 */
class AppInfo extends Common
{

    /**
     * 获取app更新信息
     * @author Mr.Li
     * @create 2021-08-23 15:20
     */
    public function getUpdateInfo()
    {
        $return = [
            'code' => 200,
            'data' => [
                'url'                   => '',
                'log'                   => '',
                'app_version'           => '',
                'app_update_status'     => ''
            ],
            'msg'  => ''
        ];
        $request = request();
        $header = $request->header();
        $platform = $header['platform'] ?? '';
        if (in_array($platform, ['ios', 'android'])) {
            $appVersion = $header['app-version'] ?? '';
            $appConfig = AppLogic::get($platform);
            if($appConfig){
                $appConfig['app_update_status'] = $appConfig['app_update_status'] ?? 0;
                $appConfig['app_version'] = $appConfig['app_version'] ?? 0;
                if($appConfig['app_version']){
                    $confVersion = str_replace(".", "", $appConfig['app_version']);
                    $appVersion = str_replace(".", "", $appVersion);//接口传参
                    if ($confVersion > $appVersion) {
                        $return['code'] = $appConfig['app_update_status'] ? 102 : 103;
                        $return['data']['url'] = $appConfig['app_path'] ?? '';
                        $return['data']['log'] = $appConfig['app_log'] ?? '';
                        $return['data']['app_version'] = $appConfig['app_version'] ?? '';
                        $return['data']['app_update_status'] = $appConfig['app_update_status'] ?? '';
                        $return['msg'] = '有新版本更新!';
                    }
                }
            }
        }
        header('Content-Type:application/json; charset=utf-8');
        exit(json_encode($return));
    }



}
